<?php 
	require "../Security/validateSession.php";
	require "../classes/DB.php";
	require "../lib/menu.php";
	require "../lib/utils.php";
	checkSession();
?>
<html><!-- InstanceBegin template="/Templates/tmpl.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Operadora IRENK</title>
<!-- InstanceEndEditable -->

<script language="javascript" src="../js/utils.js"></script>
<link href="../css/base.css" rel="stylesheet" type="text/css" />
<link href="../css/irenk.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body topmargin="0">
<table border="0" cellpadding="0" cellspacing="0" align="center" style="height:100%;">
    <tr>
    <td height="100%" width="25" class="leftMargin" ></td>
    <td><table width="900" border="0" align="center" cellpadding="0" cellspacing="0" height="100%">
        <tr>
          <td class="headerPixel" width="500" height="70" valign="top">
          	&nbsp;&nbsp;&nbsp;
            <img src="../images/temp/logo.jpg"></td>
            <td class="header" width="205" height="70"></td>
        </tr>
        <tr>
            <td class="back" colspan="2">
       	  	<table border="0" cellpadding="0" cellspacing="0" width="900" height="100%">
                	<tr>
                    	<td width="170" valign="top">
                        	<?php 
							echo '<br />&nbsp;&nbsp;&nbsp;Bienvenido(a)<br>&nbsp;&nbsp;&nbsp;'.$_SESSION["Nombre"].'<br />';
							createMenu(); 
							
							?>
                        </td>
                        <td rowspan="2" width="712" align="center" valign="top">
                        	<br />
                            <!-- InstanceBeginEditable name="submenu" -->
                            <?php 								
								$tipo='Agencia';
								$seccion=3;
								$finalize = false;
								//createSub($tipo,$seccion);
								if(isset($_POST["TCliente"]) && isset($_POST["NCliente"]) &&
										isset($_POST["FRes"]) && isset($_POST["FLim"]) && isset($_POST["TPago"]) &&
										isset($_POST["Costo"]) && isset($_POST["Saldo"]) && isset($_POST["SolEsp"]) &&
										isset($_POST["Factura"]) && isset($_POST["noches"])){
										
										$Tcl=$_POST["TCliente"];
										$Ncl=$_POST["NCliente"];
										$fRes=$_POST["FRes"];
										$fLim=$_POST["FLim"];
										$tPago=$_POST["TPago"];
										$costo=$_POST["Costo"];
										$saldo=$_POST["Saldo"];
										$solEsp=$_POST["SolEsp"];
										$status='Solicitud';
										$fact=$_POST["Factura"];
										$noches=$_POST["noches"];
										$destino=$_POST["Destinos"];
										$hotel=$_POST["Hoteles"];
										$habitacion=$_POST["tHabitaciones"];
										$profile=get_object_vars(unserialize($_SESSION['userProfile']));
										$idAgencia=$profile['data']['id_procedencia'];
										$idUsuario=$profile['data']['id_usuario'];
										//var_dump($profile);
										$db=new DB();
										$query="Insert into reservaciones (Id_Destino, Id_Hotel, Id_Tipo_Habitacion,
											    Id_Agencia, Id_Usuario, Titulo_Cliente, Nombre_Cliente, Fecha_Reservacion,
											    Fecha_Limite_Agencia, Tipo_Pago, Costo, Saldo, Solicitud_Especial, Status,
												Factura,Noches_Reservadas) 
												values('{$destino}','{$hotel}','{$habitacion}','{$idAgencia}','{$idUsuario}','{$Tcl}', 
												'{$Ncl}', '{$fRes}', '{$fLim}', '{$tPago}', '{$costo}',
												'{$saldo}', '{$solEsp}', '{$status}', '{$fact}', '{$noches}') ";
										if($r=$db->query($query)==false){
											echo "<script>alert('Error al generar la reservacion.')</script>";
										}else{
											$id=$db->idGenerated();
											echo "<script>alert('Reservacion No. {$id} generada satisfactoriamente.')</script>";
											$finalize = true;
										}
										$db->close();
									}
								//Anexar edicion de fechas de pago en esta seccion
							?>
                            <!-- InstanceEndEditable -->
                        	<!-- InstanceBeginEditable name="body" -->                            	
               		  			<table class="mainTable"  cellpadding="0" cellspacing="0" width="95%" height="90%">
                                	<tr><th>Reservaciones</th></tr>
                                    <tr><td valign="top">Reservaciones<hr /></td></tr>
                                    <tr><td valign="top">
                                    <?php 
										if (!$finalize) {
												require "IngresarR_HTML.php";
											}	else {
												require "MostrarR_HTML.php";
											}
                                    
									?>
                                    </td></tr>
                                </table>                            
                            <!-- InstanceEndEditable -->
                            <br />
                        </td>
                  </tr>
                  <tr>
                  	<td class="menuImage" width="170">&nbsp;</td>                  
                  </tr>
                </table>
            </td>
        </tr>
        <tr>
          <td colspan="2" class="footer" height="24"></td>
        </tr>
    </table></td>
  	<td width="25" class="rightMargin"></td>
	</tr>
</table>
</body>
<!-- InstanceEnd --></html>
